/*
 * @Author: 肖燕 2461435122@qq.com
 * @Date: 2024-09-06 10:31:33
 * @LastEditors: 肖燕 2461435122@qq.com
 * @LastEditTime: 2025-01-16 16:14:16
 * @FilePath: /mrismodulecash/src/assets/scripts/tools/use-columns.js
 * @Description: 自定义列设置
 */

import storage from '@/assets/scripts/store/user'
import store from '@/store'
import { ACCESS_MCHCODE, ACCESS_DEFWS } from '@/store/mutation-types'
import { findOne } from '@/services/python/find'
import { insertOne } from '@/services/python/insert'
import { setOne } from '@/services/python/set'

class TableColumns {
  // 操作的数据库表名
  collection = '结余分析列表字段'
  hosCode = storage.get(ACCESS_MCHCODE)
  userId = store.getters.userId
  workspace = storage.get(ACCESS_DEFWS)
  constructor (tableId) {
    this.tableId = tableId
  }
  setOptions () {
    return {
      hosCode: this.hosCode,
      userId: this.userId,
      workspace: this.workspace,
      tableId: this.tableId
    }
  }
  /**
   * @description: 获取列数据
   * @param {*} tableId
   * @return {*}
   */
  async getColumns () {
    const opts = this.setOptions()
    const res = await findOne(this.collection, opts, { isLoad: false })
    return res.data || null
  }
  /**
   * @description: 新增列数据
   * @return {*}
   */
  async addColumns (columns) {
    if (columns) {
      const opts = this.setOptions()
      opts.columns = columns
      const res = await insertOne(this.collection, opts)
    }
  }
  /**
   * @description: 编辑列数据
   * @return {*}
   */
  async editColumns (columns) {
    if (columns) {
      const opts = this.setOptions()
      const res = await setOne(this.collection, opts, { columns })
    }
  }
}

export {
  TableColumns
}


